package com.nine.shop.controller;


import com.nine.shop.common.ServerResponse;
import com.nine.shop.service.OrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @author Shawsw
 * Create on 2019/8/25
 */
@RestController
@RequestMapping(value = "api/shopping/order", method = RequestMethod.POST)
public class OrderController extends BaseController {
    @Resource
    private OrderService orderService;

    //后台查询所有订单

    /**
     * @Description:
     * @Param:
     * @Param:
     * @return:
     * @Author: Shawsw
     * @Date: 2019/8/27 14:11
     */
    @CrossOrigin
    @RequestMapping("allorder.do")
    public ServerResponse allOrder(@RequestParam(name = "current", defaultValue = "1") Integer current, @RequestParam(name = "size", defaultValue = "5") Integer size) {
        return orderService.findAllOrder(current, size);
    }

    //后台发货

    /**
     * @Description:
     * @Param:
     * @Param:
     * @return:
     * @Author: Shawsw
     * @Date: 2019/8/27 13:59
     */
    @CrossOrigin
    @RequestMapping("sendorder.do")
    public ServerResponse sendOrder(Integer orderId) {
        return orderService.sendOrder(orderId);
    }


    //根据user的支付密码提交订单

    /**
     * @Description:
     * @Param: payPsd：支付密码    orderslist：订单中所有货物（JSon） allcost:订单所有金额
     * @return:
     * @Author: Shawsw
     * @Date: 2019/8/27 13:50
     */
    @CrossOrigin
    @RequestMapping("payfororder.do")
    public ServerResponse payForOrder(String payPsd, @RequestParam(name = "orderslist") String orderlist, Double allcost) {
        Integer userId = super.getUser().getId();
        if (userId == null) {
            return ServerResponse.createByErrorMsg("用户未登录");
        }
        return orderService.payForOrder(userId, payPsd, orderlist, allcost);
    }

    //用户ID查询订单

    /**
     * @Description:
     * @Param:
     * @Param:
     * @return:
     * @Author: Shawsw
     * @Date: 2019/8/27 13:50
     */
    @CrossOrigin
    @RequestMapping("searchorder.do")
    public ServerResponse searchOrderByUserId(@RequestParam(name = "current", defaultValue = "1") Integer current,
                                              @RequestParam(name = "size", defaultValue = "5") Integer size) {
        Integer userId = super.getUser().getId();
        return orderService.searchOrderByUserId(size, current, userId);
    }


    //根据orderId删除订单

    /**
     * @Description:
     * @Param:
     * @Param:
     * @return:
     * @Author: Shawsw
     * @Date: 2019/8/27 13:50
     */
    @CrossOrigin
    @RequestMapping("deleteorder.do")
    public ServerResponse deleteorder(Integer orderId) {
        return orderService.delectOrderById(orderId);
    }


}
